package git.soulbgm.controller;

import git.soulbgm.common.base.BaseController;
import git.soulbgm.common.pojo.ResultData;
import git.soulbgm.common.pojo.ReturnCode;
import git.soulbgm.pojo.OrderDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import git.soulbgm.pojo.Orders;
import git.soulbgm.service.OrderService;

/**
 * 订单表
 *
 * @author SoulBGM
 * @version V1.0
 * @date 2020-11-06 17:27:16
 */
@Slf4j
@RestController
@RequestMapping("order")
public class OrderController extends BaseController<OrderService, Orders> {

    @RequestMapping(path = "createOrder", method = RequestMethod.POST)
    public ResultData createOrder(@RequestBody OrderDto dto) {
        Long orderId = null;
        try {
            orderId = service.createOrder(dto);
        } catch (Exception e) {
            log.error("创建订单失败", e);
            return ResultData.getResultData(ReturnCode.SAVE_FAIL, orderId);
        }
        return ResultData.getResultData(ReturnCode.SUCCESS, orderId);
    }
}
